home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
network
/
ka9q
/
nhclb120.zoo
/
st.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-19
|
20KB
|
1,004 lines
/* OS- and machine-dependent stuff for Atari-ST
* Adapted from the PC version to compile under Lattice C
* by Walter Doerr, DG2KK (dg2kk@cup.portal.com)
*
* 20-2-88: added code from the Atari MWC version by Rob Janssen PE1CHL
* 13-1-88: added code needed for the 871225.1 version
* 24-12-87: first version, adapted from PC.C from the 870412 release
*/
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "internet.h"
#include "iface.h"
#include "st.h"
#include "cmdparse.h"
#include "asy.h"
/* #include "stdlib.h" chkml() , malloc , free */
#ifdef LATTICE
#include "dos.h" /* dfind */
#endif
#include "osbind.h"
#ifdef MWC
#include <stat.h>
#include <path.h>
#include <time.h>
#include <signal.h>
FILE *stdprt;
extern char **environ;
#endif
#if !defined( GNUC) && !defined(MWC)
#define Crawcin() gemdos(7)
#endif
int Sixteen;
#define TRUE -1
#define FALSE 0
struct asy asy[ASY_MAX];
/* Interface list header */
struct interface *ifaces;
static struct TempList {
struct TempList *next;
char *name;
} *Head;
unsigned nasy; /* needed in v871225.1 */
char *ttbuf;
char *rsbuf; /* location of memory alloc'd for rs232 buf */
#ifdef SCREEN
char *newscreen, *newscradr; /* 32k memory allocated to 2nd video screen */
long logscreen, physcreen;
int toggle = 0; /* toggle between normal and trace screen */
int printtrace = 0; /* send trace to printer (controlled by F2) */
#endif
char *shell,*getenv(); /* Name of command shell for exec */
int rows=25; /* Number of text rows on screen (may be 50) */
/* called during init b4 anything is printed on the screen.
* PC.C does a lot of memory allocation stuff here.
* We just set the cursor to "blink" and allocate memory for a second video
* screen.
*/
ioinit()
{
char *lmalloc(); /* Takes a long arg */
unsigned long ptr;
#ifdef GNUC
/* hope GCC has not been set to 16bit int mode ! */
#define lmalloc(s) malloc(s)
#endif
#ifdef SCREEN
newscradr = lmalloc(32*1024L); /* allocate 32k for 2nd video screen */
ptr = (unsigned long)newscradr;
newscreen = (char *)((ptr+255) & 0xffffff00L); /* 256 byte boundary */
physcreen = (long)Physbase(); /* remember displayed screen address */
logscreen = (long)Logbase(); /* remember output screen address */
Cconws("\033j"); /* Save cursor position */
(void) Setscreen(newscreen,-1L,-1); /* switch to 2nd screen */
(void) Vsync(); /* wait for vsync */
Cconws("\033H\033J"); /* cursor home, clear screen */
Cconws("\033k"); /* restore cursor position */
(void) Setscreen(logscreen,-1L,-1); /* restore old screen */
(void) Vsync(); /* wait for vsync */
#endif
printf("\033v\033e\n"); /* Autowrap on, Cursor on */
(void) Cursconf(2,0); /* make the cursor blink (3=steady) */
#ifdef MWC
stdprt = fopen("prn:","w");
signal(SIGINT, SIG_IGN); /* Ignore ^C in GEMDOS I/O -- hyc */
#endif
shell = getenv("NROWS");
if (shell != NULL)
rows=atoi(shell);
shell = getenv("SHELL");
if (shell == NULL)
shell="\\bin\\gulam.prg";
}
/* Called just before exiting.
* delete temp files.
* free memory allocated to the rs-232 and midi buffers.
*/
iostop()
{
register struct TempList *tptr;
/* free memory allocated to 2nd video screen */
#ifdef SCREEN
dispscreen(0); /* switch back to original screen */
free(newscradr);
#endif
#if !defined(MWC) && !defined(GNUC)
/* delete all temp files that have accumulated. */
/* MWC does not create temp files, GNUC does, but a tmpdel()
* function will have to wait. Just use a pooper-scooper for now.
*/
(void) tmpdel();
#endif
/* free memory allocated to RS-232/MIDI I/O buffers */
while (ifaces != NULLIF) {
if (ifaces->stop != NULLFP)
(*ifaces->stop)(ifaces);
ifaces = ifaces->next;
}
tptr = Head; /* Delete all temp files */
while( tptr != NULL) {
if(tptr->name != NULL)
unlink(tptr->name);
tptr = tptr->next;
}
printf("\n");
}
#ifndef MWC
/* checks the time then ticks and updates ISS */
static int32 clkval = 0;
void
check_time()
{
int32 iss(); /* initial sequence number */
int32 clksec();
if(clkval != clksec()){
clkval = clksec();
icmpclk();
tick();
(void)iss();
}
}
/* returns the number of seconds from system clock */
static int32
clksec()
{
long tloc;
time(&tloc);
return (tloc);
}
#else
static clock_t clkval=0;
void
check_time()
{
int32 iss();
/* System clock is 200Hz or 5ms/tick. Skip 11 ticks to match the
* definition in timer.h (MSPTICK = 55 there.) -- hyc
*/
if((clock() - clkval) > 10) {
clkval = clock();
icmpclk();
tick();
(void)iss();
}
}
#endif
/* Initialize async port "dev" (adapted from PE1CHL) */
int
asy_init(dev,addr,vec,bufsize)
int16 dev;
char *addr, *vec;
unsigned bufsize;
{
register struct iorec *ip;
register struct asy *ap;
char *bufp;
#ifdef DEBUG
printf("asy_init: dev=%d bufsize=%d\n",dev,bufsize);
fflush(stdout);
#endif
ap = &asy[dev];
/* ---- Moved here from slip.c - originally by DG2KK... -- hyc ----- */
/* addr (COM Port address) is the Atari device name
* (either "AUX:" or "MIDI")
* vec (Interrupt vector) is used as a flag to indicate if
* bytes received on that interface should be sent out on
* another interface (1 = AUX: 3 = MIDI).
*/
ap->vec = atoi(vec); /* dev to resend bytes to */
ap->addr = 0; /* use as error flag */
if (strcmp(addr,"AUX:") == 0) {
ap->addr = 1;
} else if (strcmp(addr,"CON:") == 0) { /* This would be stupid. */
ap->addr = 2;
} else if (strcmp(addr,"MIDI") == 0) {
ap->addr = 3;
}
/* ----- end of paraphrase of slip.c... -- hyc ------- */
if (ap->addr == 0) {
printf("asy_init(%d): unknown interface\n",dev);
return -1;
}
/* force user to allocate more memory than he already has.
* If no memory is allocated, asy_stop() may behave funny...
*/
if (bufsize <= 256) /* only allocate a bigger buffer */
return -1;
if ((bufp = malloc(bufsize)) == NULLCHAR){
printf("asy_init(%d): no memory for rx buffer\n",dev);
return -1;
}
/* Save original IOREC values */
ip = Iorec((ap->addr)-1); /* Iorec wants AUX: = 0, MIDI = 2 */
Jdisint(12); /* disable RS-232 interrupt */
ap->in = ip;
memcpy(&ap->oldin,ip, sizeof(struct iorec)); /* prev version was
* not right ! */
if (ap->addr == RS232) { /* increase RS-232 transmit buffer? */
ip++;
ap->out = ip;
memcpy(&ap->oldout,ip,sizeof(struct iorec));
}
/* Set up receiver FIFO */
ap->in->ibuf = bufp;
ap->in->ibufsiz = bufsize;
ap->in->ibufhd = ap->in->ibuftl = 0;
ap->in->ibuflow = 0;
ap->in->ibufhi = bufsize;
if (ap->addr == RS232) {
/* clear transmitter FIFO */
ap->out->ibufhd = ap->out->ibuftl = 0;
ap->out->ibuflow = 0;
ap->out->ibufhi = ap->out->ibufsiz;
}
Jenabint(12); /* enable RS-232 interrupts */
if (ap->addr == RS232)
Rsconf(-1,0,-1,0,0,0); /* 8 bits, no parity */
#ifdef DEBUG
printf("asy_init: Iorecs in: 0x%lx out: 0x%lx\n",ap->in,ap->out);
printf(" inbuf: 0x%lx outbuf: 0x%lx\n",ap->in->ibuf,
ap->out->ibuf);
#endif
}
/* asy_stop restores old iorec and frees memory allocated to the RS-232/MIDI
* buffers. (from PE1CHL)
*/
int
asy_stop(iface)
struct interface *iface;
{
register struct asy *ap;
/* char i_state; */
#ifdef DEBUG
printf("asy_stop: iface=0x%lx dev=%d\n",iface,iface->dev);
fflush(stdout);
#endif
ap = &asy[iface->dev];
(void) Jdisint(12); /* disable RS-232 interrupts */
free(ap->in->ibuf); /* free the buffer */
/* Restore old iorecs */
memcpy(ap->in,&ap->oldin,sizeof(struct iorec));
if (ap->addr == RS232)
memcpy(ap->out,&ap->oldout,sizeof(struct iorec));
(void) Jenabint(12); /* enable RS-232 interrupts */
}
/* Set async line speed */
int
asy_speed(dev,speed)
int dev;
int speed;
{
int baud; /* int result; */
register int sp;
long sav_ssp;
if (speed <= 0 || dev >= nasy)
return -1;
asy[dev].speed = speed; /* shouldn't this be done in slip.c? */
switch (asy[dev].addr) {
case RS232:
switch (speed) {
case 300:
baud = 9; /* how slow can you get? :-) */
break;
case 1200:
baud = 7;
break;
case 2400:
baud = 4;
break;
case 4800:
baud = 2;
break;
case 9600:
baud = 1;
break;
case 19200:
baud = 0;
break;